{* $Id$ *}
{include_core file="admin/lib/header.html" title="用户展示"}
<div class="page-header border-bottom clearfix">
  <h2 class="left">用户管理<span>添加合伙人</span></h2>
  <a href="{AnUrl('user/admin')}" class="btn btn-default btn-sm right">&lt;&nbsp;返回用户列表</a>
</div>
<!--start:用户新增-->
<div class="add-form">
  <form class="js_creatForm" action="{AnUrl('user/admin/create')}" method="post" enctype="multipart/form-data">
    <table class="table" cellpadding="0" cellspacing="0">
      <input name="info[role_id]" type="hidden" value="{user_config::AGENCY}"/>
      <tr class="js_aboutDealer">
        <th><label for="" class="add-f-label">合伙人属性：</label></th>
        <td>
          <label><input type="radio" name="is_old" value="1" checked >&nbsp;老合伙人&nbsp;</label>
          <label><input type="radio" name="is_old" value="0">&nbsp;新合伙人&nbsp;</label>
        </td>
      </tr>
      <tr>
        <th><label for="" class="add-f-label">用户名：</label></th>
        <td>
          <input name="info[user_name]" style="width:490px;" type="text" class="add-f-ipt1">
          <div class="tips">输入用户名,以后用于登录</div>
        </td>
      </tr>
      <tr>
        <th><label for="" class="add-f-label">手机号码：</label></th>
        <td>
          <input name="info[mobile]" style="width:490px;" type="text" class="add-f-ipt1 js_mobile">
          <div class="tips">输入手机号码</div>
        </td>
      </tr>
      <!-- <tr>
        <th><label for="" class="add-f-label">密码：</label></th>
        <td>
          <input style="width:490px;" type="text" class="add-f-ipt1 js_password">
          <div class="tips"><span style="line-height: 34px;color: #f00;margin-right: 10px;">*</span>输入密码</div>
        </td>
      </tr> -->
      <tr>
        <th><label for="" class="add-f-label">密码：</label></th>
        <td>
          <input name="info[password]" style="width:490px;" type="text" class="add-f-ipt1">
          <div class="tips"><span style="line-height: 34px;color: #f00;margin-right: 10px;">*</span>输入密码</div>
        </td>
      </tr>
      <tr>
        <th><label for="" class="add-f-label">真实姓名：</label></th>
        <td>
          <input name="info[realname]" style="width:490px;" type="text" class="add-f-ipt1 js_rePassword">
          <div class="tips"><span style="line-height: 34px;color: #f00;margin-right: 10px;">*</span>请输入真实姓名</div>
        </td>
      </tr>
      <!--<tr>-->
        <!--<th><label for="" class="add-f-label">昵称：</label></th>-->
        <!--<td>-->
          <!--<input name="info[nickname]" style="width:490px;" type="text" class="add-f-ipt1 js_rePassword">-->
          <!--<div class="tips"><span style="line-height: 34px;color: #f00;margin-right: 10px;">*</span>请输入昵称</div>-->
        <!--</td>-->
      <!--</tr>-->
      <tr>
        <th><label for="" class="add-f-label">邮箱地址：</label></th>
        <td>
          <input name="info[email]" style="width:490px;" type="text" class="add-f-ipt1 js_email">
          <div class="tips">输入邮箱地址</div>
        </td>
      </tr>
      <tr class="js_aboutDealer">
        <th><label for="" class="add-f-label">微信号：</label></th>
        <td>
          <input name="info[weixin]" style="width:490px;" type="text" class="add-f-ipt1">
          <div class="tips"><span style="line-height: 34px;color: #f00;margin-right: 10px;">*</span>输入微信号码</div>
        </td>
      </tr>
      {* <tr class="js_aboutDealer">
        <th><label for="" class="add-f-label">仓库地址：</label></th>
        <td>
          <select name="province" class="js_provinceList" style="width:150px;">
              <option value="000000" selected="selected">请选择省份</option>
          </select>
          <select name="city" class="js_cityList" style="width:150px;display:none">
              <option value="000000" selected="selected">请选择城市</option>
          </select>
          <select name="county" class="js_countyList" style="width:150px;display:none">
              <option value="000000" selected="selected">请选择地区</option>
          </select>
          <div class="tips"><span style="line-height: 34px;color: #f00;margin-right: 10px;">*</span>选择仓库地址</div>
        </td>
      </tr>
      <tr class="js_aboutDealer">
        <th><label for="" class="add-f-label">详细仓库地址:</label></th>
        <td>
          <input name="info[store_house]" style="width:490px;" type="text" class="add-f-ipt1">
          <div class="tips"><span style="line-height: 34px;color: #f00;margin-right: 10px;">*</span>输入仓库地址</div>
        </td>
      </tr> *}
      <tr class="js_aboutDealer">
        <th><label for="" class="add-f-label">银行名称：</label></th>
        <td>
          <input name="info[bank_name]" style="width:490px;" type="text" class="add-f-ipt1">
          <div class="tips"><span style="line-height: 34px;color: #f00;margin-right: 10px;">*</span>输入银行名称</div>
        </td>
      </tr>
      <tr class="js_aboutDealer">
        <th><label for="" class="add-f-label">开户行：</label></th>
        <td>
          <input name="info[account_bank]" style="width:490px;" type="text" class="add-f-ipt1 " max-length="100">
          <div class="tips">输入开户行名称</div>
        </td>
      </tr>
      <tr class="js_aboutDealer">
        <th><label for="" class="add-f-label">身份证号码：</label></th>
        <td>
          <input name="info[id_card_no]" style="width:490px;" type="text" class="add-f-ipt1 " max-length="100">
          <div class="tips">输入身份证号码</div>
        </td>
      </tr>
      {* <tr class="js_aboutDealer">
        <th><label for="" class="add-f-label">家庭住址：</label></th>
        <td>
          <input name="info[address]" style="width:490px;" type="text" class="add-f-ipt1 " max-length="100">
          <div class="tips">输入家庭住址</div>
        </td>
      </tr> *}
      <tr class="js_aboutDealer">
        <th><label for="" class="add-f-label">银行卡号：</label></th>
        <td>
          <input name="info[bank_code]" style="width:490px;" type="text" class="add-f-ipt1 js_email">
          <div class="tips"><span style="line-height: 34px;color: #f00;margin-right: 10px;">*</span>输入银行卡号</div>
        </td>
      </tr>
      {* <tr>
        <th><label for="" class="add-f-label">选择默认助理：</label></th>
        <td>
          <select class="add-f-slt1" name="info[assistant_user_id]" style="width:200px;">
            <option value="0" selected>请选择默认助理</option>
            {foreach $assistant_list as $k=>$v}
              <option value="{$v.id}">{$v.realname}---------{$v.mobile}</option>
            {/foreach}
          </select>
          <div class="tips">请选择默认助理</div>
        </td>
      </tr>
      <tr>
        <th><label for="" class="add-f-label">选择大区经理：</label></th>
        <td>
          <select class="add-f-slt1" name="info[area_manager_id]" style="width:200px;">
            <option value="0" selected>请选择大区经理</option>
            {foreach $area_manager_list as $k=>$v}
              <option value="{$v.id}">{$v.realname}---------{$v.mobile}</option>
            {/foreach}
          </select>
          <div class="tips">选择大区经理</div>
        </td>
      </tr> *}
      <tr class="js_aboutDealer">
        <th valign="top"><label class="add-f-label" for="">上传身份证正面照：</label></th>
        <td class="perUpOuter">
          <div class="clearfix">
            <div class="btn-upload left">
              <a href="javascript:void(0);"><i class="icon-upload"></i>上传正面照</a>
              <input type="file" class="js_upFile" name="cert_idcard_front">
            </div>
            <span class="tips left">&nbsp;&nbsp;&nbsp;图片比例：528*333</span>
          </div>
          <div class="js_upFileBox">
              <div class="js_upFileBox">
              {if $user_store_info.cert_idcard_front}
              <img src="{_image($user_store_info.cert_idcard_front, 'list')}" width="270">
              {else}
              <!-- <img src="{$smarty.const.SITE_URL}/images/m/default/focus_default.jpg" width="270"> -->
              {/if}
          </div>
          </div>
        </td>
      </tr>
      <tr class="js_aboutDealer">
        <th valign="top"><label class="add-f-label" for="">上传身份证背面照：</label></th>
        <td class="perUpOuter">
          <div class="clearfix">
            <div class="btn-upload left">
              <a href="javascript:void(0);"><i class="icon-upload"></i>上传背面照</a>
              <input type="file" class="js_upFile" name="cert_idcard_back">
            </div>
            <span class="tips left">&nbsp;&nbsp;&nbsp;图片比例：528*333</span>
          </div>
          <div class="js_upFileBox">
              <div class="js_upFileBox">
              {if $user_store_info.cert_idcard_back}
              <img src="{_image($user_store_info.cert_idcard_back, 'list')}" width="270">
              {else}
              <!-- <img src="{$smarty.const.SITE_URL}/images/m/default/focus_default.jpg" width="270"> -->
              {/if}
          </div>
          </div>
        </td>
      </tr>
      <tr class="js_aboutDealer">
        <th valign="top"><label class="add-f-label" for="">上传合同照：</label></th>
        <td class="perUpOuter">
          <div class="clearfix">
            <div class="btn-upload left">
              <a href="javascript:void(0);"><i class="icon-upload"></i>上传合同照</a>
              <input type="file" class="js_upFile" name="cert_company">
            </div>
            <span class="tips left">&nbsp;&nbsp;&nbsp;图片比例：1107*690</span>
          </div>
          <div class="js_upFileBox">
              <div class="js_upFileBox">
              {if $user_store_info.cert_company}
              <img src="{_image($user_store_info.cert_company, 'list')}" width="270">
              {else}
              <!-- <img src="{$smarty.const.SITE_URL}/images/m/default/focus_default.jpg" width="270"> -->
              {/if}
          </div>
          </div>
        </td>
      </tr>
      <tr>
        <th><label for="" class="add-f-label">用户状态：</label></th>
        <td>{$info.status}
          <input type="radio" value="1" name="info[status]" checked="checked" />正常 &nbsp;&nbsp;
          <input type="radio" value="0" name="info[status]" />锁定
        </td>
      </tr>
      <tr><th>&nbsp;</th><td class="noborder"><button type="submit" class="btn btn-success js_submit">&nbsp;&nbsp;&nbsp;确认&nbsp;&nbsp;&nbsp;</button></td></tr>
    </table>
  </form>
</div>
<!--end:用户新增-->
<script>
$(function(){
 // 初始化用户编辑页面
  
//初始化省份列表
  $.ajax({
    url : 'area/admin/ajax_get_provinces',
    type : 'get',
    dataType : 'json',
    success : function(province_list){
      for (var i in province_list) {
        var opt = $('<option value="'+province_list[i]['area_code']+'">'+province_list[i]['area']+'</option>');
        $('.js_provinceList').append(opt);
      }

      {if $area['province_info']}
        $('.js_provinceList').val("{$area['province_info']['area_code']}");
        //触发请求
        $('.js_provinceList').change();
      {/if}

      {if $area['city_info']}
        $('.js_provinceList').val("{$area.province_info.area_code}");
        $('.js_cityList').val("{$area.city_info.area_code}");
        $('.js_cityList').change();
        $('.js_countyList').val("{$area['county_info']['area_code']}");
      {/if}
    }
  });
  
  $('.js_provinceList').change(function(){
    //获取值
      if($(this).val() !== '000000'){
        var province = $(this).val();
        $('.js_cityList').fadeIn();
        $('.js_countyList').fadeOut();
        $('.js_countyList').val('000000');
      }else{
        $('.js_cityList').fadeOut();
        $('.js_cityList').val('000000');
        $('.js_countyList').fadeOut();
        $('.js_countyList').val('000000');
        
        return false;
      }
      $('.js_cityList').empty();
      $('.js_cityList').append('<option value="000000">请选择城市</option>');
      $('.js_countyList').empty();
      $('.js_countyList').append('<option value="000000">请选择区(县)</option>');

      //发送ajax
      $.ajax({
        url : 'area/admin/ajax_get_citys?province_code='+province,
        success : function(city_list){
          for (var i in city_list) {
            var opt = $('<option value="'+city_list[i]['area_code']+'">'+city_list[i]['area']+'</option>');
            $('.js_cityList').append(opt);
          }

          {if $area.city_info}
            $('.js_cityList').val("{$area.city_info.area_code}");
          {/if}
        },
        type : 'get',
        dataType : 'json',
        async : false,
      });


    });
    //城市
    $('.js_cityList').change(function(){
      if ( $('.js_provinceList').val() === '000000' || $('.js_cityList').val() === '000000') {
          
          $('.js_countyList').val('000000');
          $('.js_countyList').fadeOut();
      } else {
        $('.js_countyList').fadeIn();
        $('.js_countyList').val('000000');
      }

      $('.js_countyList').empty();
      $('.js_countyList').append('<option value="000000">请选择区(县)</option>');

      //获取省份的key和值
      var province_code = $('.js_provinceList').val();
      var pro_text = $('.js_provinceList').text();

      //获取城市的值
      var city_code = $(this).val();

      //发送ajax
      $.ajax({
        url : 'area/admin/ajax_get_countys?province_code='+province_code+'&city_code='+city_code,
        type : 'get',
        dataType : 'json',
        success : function(county_list){
          for (var i in county_list) {
            var opt = $('<option value="'+county_list[i]['area_code']+'">'+county_list[i]['area']+'</option>');
            $('.js_countyList').append(opt);
          }

          {if $area['county_info']}
            $('.js_countyList').fadeIn();
            $('.js_countyList').val("{$area['county_info']['area_code']}");
          {/if}
        }
      });
      
    });
  
  
    
  // 提交验证
  $('.js_submit').click(function(e){
      
    e.preventDefault();
    var userName      = $.trim($('.js_userName').val());
    var password      = $.trim($('input[name="info[password]"]').val());
    var email         = $.trim($('.js_email').val());
    var role_id       = $('.js_role option:selected').val();
    var parent_id     = $('select[name="info[parent_id]"]').val();
    var mobile        = $.trim($('.js_mobile').val());
    var weixin        = $.trim($('input[name="info[weixin]"]').val());
    var bank_name     = $.trim($('input[name="info[bank_name]"]').val());
    var bank_code     = $.trim($('input[name="info[bank_code]"]').val());
    var store_house   = $.trim($('input[name="info[store_house]"]').val());
//    var nickname      = $.trim($('input[name="info[nickname]"]'));
    // var realname      = $.trim($('input[name="info[realname]"]').val());
    var province      = $.trim($('select[name="province"]').val());
    if(role_id == 0){
      showMsg('请选择用户所属组');
      return;
    }
    
/*     if (!province || province == '000000') {
        showMsg('请选择仓库地址!');
        return false;
    } */
    
    // 真实姓名不能为空
    if ($('input[name="info[realname]"]').val() == '') {
        showMsg('真实姓名不能为空!');
        return false;
    }
    
    // 真实姓名不能为空
//    if ($('input[name="info[nickname]"]').val() == '') {
//        showMsg('昵称不能为空!');
//        return false;
//    }
    
    if(is_pwd_null(password)) {
      showMsg('密码内不能存在空字符!');
      return;
    }
    if (getStringLen(password) < 6) {
      showMsg('密码不能少于6个字符!');
      return;
    }
    
    if (email) {
      if (!checkStr(email, 'mail')) {
        showMsg('邮箱格式不正确!');
        return;
      }
    }
    if(mobile) {
      if(!checkStr(mobile, 'mobile')) {
        showMsg('手机号码格式不正确!');
        return;
      }
    }
    
    if (!weixin) {
        showMsg('微信号不能为空!');
        return false;
    }
    if (!mobile) {
        showMsg('手机号不能为空!');
        return false;
    }
    if (!bank_name) {
        showMsg('银行名称不能为空!');
        return false;
    }
    if (!bank_code) {
        showMsg('银行卡号不能为空!');
        return false;
    }

    $('.js_creatForm').submit();
  });
  
//上传图片预览
  $(".js_upFile").each(function(i){
    $(this).change(function(e){
      handleFileSelect($(this), 270);
    });
  });
  
  
  
});

</script>
{include_core file="admin/lib/footer.html"}